using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

internal static class Class28
{
	internal static readonly string string_0 = "ClownFishAutoCode";

	internal static readonly int int_0 = 1;

	internal static readonly int int_1 = 2;

	internal static readonly int int_2 = 3;

	internal static readonly int int_3 = 4;

	private static readonly string string_1 = "___";

	private static string smethod_0()
	{
		return "f" + Guid.NewGuid().ToString("N");
	}

	private static Class26 smethod_1(Type type_0)
	{
		return new Class26
		{
			type_0 = type_0,
			string_0 = Class28.string_0,
			string_1 = Class28.smethod_0(),
			string_5 = Class28.smethod_0(),
			string_6 = Class28.smethod_0(),
			string_7 = Class28.smethod_0(),
			string_8 = Class28.smethod_0(),
			string_9 = Class28.smethod_0(),
			string_10 = Class28.smethod_0(),
			string_11 = Class28.smethod_0(),
			string_12 = Class28.smethod_0(),
			string_2 = Class28.smethod_0(),
			string_3 = Class28.smethod_0(),
			string_4 = Class28.smethod_0(),
			dictionary_0 = new Dictionary<string, string>()
		};
	}

	private static string smethod_2(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("using System;");
		stringBuilder.AppendLine("using System.Collections.Generic;");
		stringBuilder.AppendLine("using System.Text;");
		stringBuilder.AppendLine("using System.Data;");
		stringBuilder.AppendLine("using System.Data.Common;");
		stringBuilder.AppendLine("using ClownFish;");
		stringBuilder.AppendLine("");
		stringBuilder.AppendLine("");
		stringBuilder.Append("namespace ").AppendLine(class26_0.string_0);
		stringBuilder.AppendLine("{");
		stringBuilder.AppendFormat("public static class {0}\r\n", class26_0.string_1);
		stringBuilder.AppendLine("{");
		if (class26_0.type_0.smethod_6())
		{
			stringBuilder.AppendLine(Class28.smethod_4(class26_0));
			stringBuilder.AppendLine(Class28.smethod_6(class26_0));
			stringBuilder.AppendLine(Class28.smethod_8(class26_0));
			stringBuilder.AppendLine(Class28.smethod_9(class26_0));
			stringBuilder.AppendLine(Class28.smethod_10(class26_0));
			stringBuilder.AppendLine(Class28.smethod_11(class26_0));
			stringBuilder.AppendLine(Class28.smethod_12(class26_0));
			stringBuilder.AppendLine(Class28.smethod_14(class26_0));
			stringBuilder.AppendLine(Class28.smethod_17(class26_0));
		}
		else
		{
			stringBuilder.AppendLine(Class28.smethod_5(class26_0));
		}
		stringBuilder.AppendLine(Class28.smethod_3(class26_0));
		stringBuilder.AppendLine("}\r\n}");
		return stringBuilder.ToString();
	}

	private static string smethod_3(Class26 class26_0)
	{
		FieldInfo[] fields = class26_0.type_0.GetFields(BindingFlags.Instance | BindingFlags.Public);
		PropertyInfo[] properties = class26_0.type_0.GetProperties(BindingFlags.Instance | BindingFlags.Public);
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("public static object {0}(object obj, string name){{\r\n", class26_0.string_3);
		stringBuilder.AppendFormat("{0} item = ({0})obj;\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendLine("switch( name ) {");
		FieldInfo[] array = fields;
		for (int i = 0; i < array.Length; i++)
		{
			FieldInfo fieldInfo = array[i];
			stringBuilder.AppendFormat("case \"{0}\": ", fieldInfo.Name);
			if (fieldInfo.FieldType.smethod_2())
			{
				stringBuilder.AppendFormat("{{if (item.{0}.HasValue) return item.{0}.Value; else return null;}}\r\n", fieldInfo.Name);
			}
			else
			{
				stringBuilder.AppendFormat("return item.{0};\r\n", fieldInfo.Name);
			}
		}
		PropertyInfo[] array2 = properties;
		for (int j = 0; j < array2.Length; j++)
		{
			PropertyInfo propertyInfo = array2[j];
			if (!propertyInfo.smethod_9() && propertyInfo.CanRead)
			{
				stringBuilder.AppendFormat("case \"{0}\": ", propertyInfo.Name);
				if (propertyInfo.PropertyType.smethod_2())
				{
					stringBuilder.AppendFormat("{{if (item.{0}.HasValue) return item.{0}.Value; else return null;}}\r\n", propertyInfo.Name);
				}
				else
				{
					stringBuilder.AppendFormat("return item.{0};\r\n", propertyInfo.Name);
				}
			}
		}
		stringBuilder.AppendLine("default: throw new ArgumentOutOfRangeException(\"name\", string.Format(\"Property or field {0} not found.\", name)); }");
		stringBuilder.AppendLine("}");
		stringBuilder.AppendFormat("public static void {0}(object obj, string name, object value){{\r\n", class26_0.string_4);
		stringBuilder.AppendFormat("{0} item = ({0})obj;\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendLine("switch( name ) {");
		FieldInfo[] array3 = fields;
		for (int k = 0; k < array3.Length; k++)
		{
			FieldInfo fieldInfo2 = array3[k];
			stringBuilder.AppendFormat("case \"{0}\": ", fieldInfo2.Name);
			if (fieldInfo2.FieldType.smethod_2())
			{
				stringBuilder.AppendFormat("item.{0} = ({1})Convert.ChangeType(value, typeof({1})); break;\r\n", fieldInfo2.Name, fieldInfo2.FieldType.smethod_3().smethod_7());
			}
			else if (fieldInfo2.FieldType.IsValueType && !fieldInfo2.FieldType.IsEnum)
			{
				stringBuilder.AppendFormat("item.{0} = ({1})Convert.ChangeType(value, typeof({1})); break;\r\n", fieldInfo2.Name, fieldInfo2.FieldType.smethod_7());
			}
			else
			{
				stringBuilder.AppendFormat("item.{0} = ({1})value; break;\r\n", fieldInfo2.Name, fieldInfo2.FieldType.smethod_7());
			}
		}
		PropertyInfo[] array4 = properties;
		for (int l = 0; l < array4.Length; l++)
		{
			PropertyInfo propertyInfo2 = array4[l];
			if (!propertyInfo2.smethod_9() && propertyInfo2.CanWrite)
			{
				stringBuilder.AppendFormat("case \"{0}\": ", propertyInfo2.Name);
				if (propertyInfo2.PropertyType.smethod_2())
				{
					stringBuilder.AppendFormat("item.{0} = ({1})Convert.ChangeType(value, typeof({1})); break;\r\n", propertyInfo2.Name, propertyInfo2.PropertyType.smethod_3().smethod_7());
				}
				else if (propertyInfo2.PropertyType.IsValueType && !propertyInfo2.PropertyType.IsEnum)
				{
					stringBuilder.AppendFormat("item.{0} = ({1})Convert.ChangeType(value, typeof({1})); break;\r\n", propertyInfo2.Name, propertyInfo2.PropertyType.smethod_7());
				}
				else
				{
					stringBuilder.AppendFormat("item.{0} = ({1})value; break;\r\n", propertyInfo2.Name, propertyInfo2.PropertyType.smethod_7());
				}
			}
		}
		stringBuilder.AppendLine("default: throw new ArgumentOutOfRangeException(\"name\", string.Format(\"Property or field {0} not found.\", name)); }");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static string smethod_4(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("public static object {0}(int key, object dataSource, int state){{\r\n", class26_0.string_2);
		stringBuilder.AppendLine("switch( key ) {");
		stringBuilder.AppendLine("case 1:");
		stringBuilder.AppendFormat("return {0}((DbDataReader)dataSource);\r\n", class26_0.string_7);
		stringBuilder.AppendLine("case 2:");
		stringBuilder.AppendFormat("return {0}((DataTable)dataSource);\r\n", class26_0.string_9);
		stringBuilder.AppendLine("case 3:");
		stringBuilder.AppendFormat("return {0}((DbDataReader)dataSource, state);\r\n", class26_0.string_8);
		stringBuilder.AppendLine("case 4:");
		stringBuilder.AppendFormat("return {0}((DataTable)dataSource, state);\r\n", class26_0.string_10);
		stringBuilder.AppendLine("default:");
		stringBuilder.AppendLine("throw new ArgumentOutOfRangeException(\"key\");");
		stringBuilder.AppendLine("}");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static string smethod_5(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("public static object {0}(int key, object dataSource, int state){{\r\n", class26_0.string_2);
		stringBuilder.AppendLine("throw new NotSupportedException();");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static string smethod_6(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append("private sealed class ").Append(class26_0.string_5).AppendLine(" {");
		Class28.smethod_7(class26_0.type_0, class26_0.dictionary_0, string.Empty);
		foreach (KeyValuePair<string, string> current in class26_0.dictionary_0)
		{
			stringBuilder.AppendFormat("public int {0};\r\n", current.Value);
		}
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static void smethod_7(Type type_0, Dictionary<string, string> dictionary_0, string string_2)
	{
		Class6 @class = type_0.smethod_0(false);
		foreach (KeyValuePair<string, Class34> current in @class.method_8())
		{
			if (!current.Value.method_1().IgnoreLoad && !current.Value.method_1().bool_0)
			{
				dictionary_0[string_2 + current.Key] = Class28.smethod_0();
			}
		}
		foreach (KeyValuePair<string, Class34> current2 in @class.method_8())
		{
			if (!current2.Value.method_1().IgnoreLoad && current2.Value.method_1().bool_0)
			{
				Class28.smethod_7(current2.Value.method_3(), dictionary_0, string_2 + current2.Key + Class28.string_1);
			}
		}
	}

	private static string smethod_8(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("public static {0} {1}(DbDataReader reader) {{\r\n", class26_0.type_0.smethod_7(), class26_0.string_7);
		stringBuilder.AppendFormat("{0} xx = {1}(reader);\r\n", class26_0.string_5, class26_0.string_6);
		stringBuilder.AppendLine("if( reader.Read() ) {");
		stringBuilder.AppendFormat("{0} item = new {0}();\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendFormat("{0}(reader, xx, item);\r\n", class26_0.string_11);
		stringBuilder.AppendLine("return item;");
		stringBuilder.AppendLine("}");
		stringBuilder.AppendLine("return null;");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static string smethod_9(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("public static List<{0}> {1}(DbDataReader reader, int capacity) {{\r\n", class26_0.type_0.smethod_7(), class26_0.string_8);
		stringBuilder.AppendFormat("{0} xx = {1}(reader);\r\n", class26_0.string_5, class26_0.string_6);
		stringBuilder.AppendFormat("List<{0}> list = new List<{0}>(capacity);\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendLine("while( reader.Read() ) {");
		stringBuilder.AppendFormat("{0} item = new {0}();\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendFormat("{0}(reader, xx, item);\r\n", class26_0.string_11);
		stringBuilder.AppendLine("list.Add(item);");
		stringBuilder.AppendLine("}");
		stringBuilder.AppendLine("return list;");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static string smethod_10(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("public static {0} {1}(DataTable table) {{\r\n", class26_0.type_0.smethod_7(), class26_0.string_9);
		stringBuilder.AppendLine("if( table.Rows.Count == 0 ) return null;");
		stringBuilder.AppendFormat("{0} xx = {1}(table);\r\n", class26_0.string_5, class26_0.string_6);
		stringBuilder.AppendFormat("{0} item = new {0}();\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendLine("DataRow row = table.Rows[0];");
		stringBuilder.AppendFormat("{0}(row, xx, item);\r\n", class26_0.string_12);
		stringBuilder.AppendLine("return item;");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static string smethod_11(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("public static List<{0}> {1}(DataTable table, int capacity) {{\r\n", class26_0.type_0.smethod_7(), class26_0.string_10);
		stringBuilder.AppendLine("if( table.Rows.Count == 0 )");
		stringBuilder.AppendFormat("return new List<{0}>(0);\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendFormat("{0} xx = {1}(table);\r\n", class26_0.string_5, class26_0.string_6);
		stringBuilder.AppendFormat("List<{0}> list = new List<{0}>(capacity);\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendLine("foreach( DataRow row in table.Rows ) {");
		stringBuilder.AppendFormat("{0} item = new {0}();\r\n", class26_0.type_0.smethod_7());
		stringBuilder.AppendFormat("{0}(row, xx, item);\r\n", class26_0.string_12);
		stringBuilder.AppendLine("list.Add(item);");
		stringBuilder.AppendLine("}");
		stringBuilder.AppendLine("return list;");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static string smethod_12(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("private static {0} {1}(object dataSource)\r\n", class26_0.string_5, class26_0.string_6);
		stringBuilder.AppendLine("{");
		stringBuilder.AppendLine("string[] cc = null;");
		stringBuilder.AppendLine("DbDataReader reader = dataSource as DbDataReader;");
		stringBuilder.AppendLine("if( reader != null ) cc = ClownFish.DbHelper.GetColumnNames(reader);");
		stringBuilder.AppendLine("else cc = ClownFish.DbHelper.GetColumnNames((DataTable)dataSource);");
		stringBuilder.AppendLine();
		stringBuilder.AppendFormat("{0} xx = new {0}();\r\n", class26_0.string_5);
		Class28.smethod_13(class26_0, class26_0.type_0, stringBuilder, string.Empty, string.Empty);
		stringBuilder.AppendLine("return xx;");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static void smethod_13(Class26 class26_0, Type type_0, StringBuilder stringBuilder_0, string string_2, string string_3)
	{
		Class6 @class = type_0.smethod_0(false);
		foreach (KeyValuePair<string, Class34> current in @class.method_8())
		{
			if (!current.Value.method_1().IgnoreLoad && !current.Value.method_1().bool_0)
			{
				stringBuilder_0.AppendFormat("xx.{0} = ClownFish.MyExtensions.FindIndex(cc, \"{1}\");\r\n", class26_0.dictionary_0[string_2 + current.Key], string_3 + current.Value.method_1().Alias);
			}
		}
		foreach (KeyValuePair<string, Class34> current2 in @class.method_8())
		{
			if (!current2.Value.method_1().IgnoreLoad && current2.Value.method_1().bool_0)
			{
				Class28.smethod_13(class26_0, current2.Value.method_3(), stringBuilder_0, string_2 + current2.Key + Class28.string_1, string_3 + current2.Value.method_1().SubItemPrefix);
			}
		}
	}

	private static string smethod_14(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("private static void {0}(DbDataReader reader, {1} xx, {2} item) {{\r\n", class26_0.string_11, class26_0.string_5, class26_0.type_0.smethod_7());
		Class28.smethod_16(class26_0, class26_0.type_0, stringBuilder, string.Empty, "item.");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static string smethod_15(Class34 class34_0)
	{
		Type type = class34_0.method_3();
		if (type == TypeDefine.TypeInt)
		{
			return "reader.GetInt32";
		}
		if (type == TypeDefine.TypeString)
		{
			return "reader.GetString";
		}
		if (type == TypeDefine.TypeDateTime)
		{
			return "reader.GetDateTime";
		}
		if (type == TypeDefine.TypeDecimal)
		{
			return "reader.GetDecimal";
		}
		if (type == TypeDefine.TypeBool)
		{
			return "reader.GetBoolean";
		}
		if (type == TypeDefine.TypeLong)
		{
			return "reader.GetInt64";
		}
		if (type == TypeDefine.TypeShort)
		{
			return "reader.GetInt16";
		}
		if (type == TypeDefine.TypeFloat)
		{
			return "reader.GetFloat";
		}
		if (type == TypeDefine.TypeDouble)
		{
			return "reader.GetDouble";
		}
		if (type == TypeDefine.TypeGuid)
		{
			return "reader.GetGuid";
		}
		if (type == TypeDefine.TypeByte)
		{
			return "reader.GetByte";
		}
		return string.Format("({0})reader.GetValue", class34_0.method_3().smethod_7());
	}

	private static void smethod_16(Class26 class26_0, Type type_0, StringBuilder stringBuilder_0, string string_2, string string_3)
	{
		Class6 @class = type_0.smethod_0(false);
		foreach (KeyValuePair<string, Class34> current in @class.method_8())
		{
			if (!current.Value.method_1().IgnoreLoad && !current.Value.method_1().bool_0)
			{
				stringBuilder_0.AppendFormat("if( xx.{0} >= 0 ) {{\r\n", class26_0.dictionary_0[string_2 + current.Key]);
				if (current.Value.method_3() == TypeDefine.TypeChar)
				{
					stringBuilder_0.AppendFormat("{0}{1} = reader.GetString(xx.{2})[0];\r\n", string_3, current.Key, class26_0.dictionary_0[string_2 + current.Key]);
				}
				else if (current.Value.method_3() == typeof(char?))
				{
					stringBuilder_0.AppendFormat("object val = reader.GetValue(xx.{0});\r\n", class26_0.dictionary_0[string_2 + current.Key]);
					stringBuilder_0.AppendLine("if( val != null && DBNull.Value.Equals(val) == false ) {");
					stringBuilder_0.AppendLine("string str = val.ToString();");
					stringBuilder_0.AppendLine("if( str.Length > 0 ) ");
					stringBuilder_0.AppendFormat("{0}{1} = str[0];\r\n", string_3, current.Key);
					stringBuilder_0.AppendLine("}");
				}
				else if (current.Value.method_3().IsValueType && !current.Value.method_3().smethod_2())
				{
					stringBuilder_0.AppendFormat("{0}{1} = {2}(xx.{3});\r\n", new object[]
					{
						string_3,
						current.Key,
						Class28.smethod_15(current.Value),
						class26_0.dictionary_0[string_2 + current.Key]
					});
				}
				else
				{
					stringBuilder_0.AppendFormat("object val = reader.GetValue(xx.{0});\r\n", class26_0.dictionary_0[string_2 + current.Key]);
					stringBuilder_0.AppendLine("if( val != null && DBNull.Value.Equals(val) == false )");
					stringBuilder_0.AppendFormat("{0}{1} = ({2})(val);\r\n", string_3, current.Key, current.Value.method_3().smethod_2() ? current.Value.method_3().smethod_3().smethod_7() : current.Value.method_3().smethod_7());
				}
				stringBuilder_0.AppendLine("}");
			}
		}
		foreach (KeyValuePair<string, Class34> current2 in @class.method_8())
		{
			if (!current2.Value.method_1().IgnoreLoad && current2.Value.method_1().bool_0)
			{
				stringBuilder_0.AppendFormat("{0}{1} = new {2}();\r\n", string_3, current2.Key, current2.Value.method_3().smethod_7());
				Class28.smethod_16(class26_0, current2.Value.method_3(), stringBuilder_0, string_2 + current2.Key + Class28.string_1, string_3 + current2.Key + ".");
			}
		}
	}

	private static string smethod_17(Class26 class26_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendFormat("private static void {0}(DataRow row, {1} xx, {2} item) {{\r\n", class26_0.string_12, class26_0.string_5, class26_0.type_0.smethod_7());
		Class28.smethod_18(class26_0, class26_0.type_0, stringBuilder, string.Empty, "item.");
		stringBuilder.AppendLine("}");
		return stringBuilder.ToString();
	}

	private static void smethod_18(Class26 class26_0, Type type_0, StringBuilder stringBuilder_0, string string_2, string string_3)
	{
		Class6 @class = type_0.smethod_0(false);
		foreach (KeyValuePair<string, Class34> current in @class.method_8())
		{
			if (!current.Value.method_1().IgnoreLoad && !current.Value.method_1().bool_0)
			{
				stringBuilder_0.AppendFormat("if( xx.{0} >= 0 ) {{\r\n", class26_0.dictionary_0[string_2 + current.Key]);
				if (current.Value.method_3().IsValueType && !current.Value.method_3().smethod_2())
				{
					stringBuilder_0.AppendFormat("{0}{1} = ({2})(row[xx.{3}]);\r\n", new object[]
					{
						string_3,
						current.Key,
						current.Value.method_3().smethod_7(),
						class26_0.dictionary_0[string_2 + current.Key]
					});
				}
				else
				{
					stringBuilder_0.AppendFormat("object val = row[xx.{0}];\r\n", class26_0.dictionary_0[string_2 + current.Key]);
					stringBuilder_0.AppendLine("if( val != null && DBNull.Value.Equals(val) == false )");
					stringBuilder_0.AppendFormat("{0}{1} = ({2})(val);\r\n", string_3, current.Key, current.Value.method_3().smethod_2() ? current.Value.method_3().smethod_3().smethod_7() : current.Value.method_3().smethod_7());
				}
				stringBuilder_0.AppendLine("}");
			}
		}
		foreach (KeyValuePair<string, Class34> current2 in @class.method_8())
		{
			if (!current2.Value.method_1().IgnoreLoad && current2.Value.method_1().bool_0)
			{
				stringBuilder_0.AppendFormat("{0}{1} = new {2}();\r\n", string_3, current2.Key, current2.Value.method_3().smethod_7());
				Class28.smethod_18(class26_0, current2.Value.method_3(), stringBuilder_0, string_2 + current2.Key + Class28.string_1, string_3 + current2.Key + ".");
			}
		}
	}

	public static List<Class27> smethod_19(List<Type> list_0)
	{
		if (list_0 != null && list_0.Count != 0)
		{
			List<Class27> list = new List<Class27>(list_0.Count);
			foreach (Type current in list_0)
			{
				Class27 @class = new Class27();
				@class.class26_0 = Class28.smethod_1(current);
				@class.string_0 = Class28.smethod_2(@class.class26_0);
				list.Add(@class);
			}
			return list;
		}
		return new List<Class27>();
	}
}
